package com.njxzc.igo.service;

import java.util.Comparator;

import com.njxzc.igo.model.Products;

public class ProductsComparator implements SortComparatorProvider {

	
	public Comparator<Products> produce(String kind) {
		if (kind.equals("price")) {
			return new SortByPrice();
		} else if (kind.equals("saleamount")) {
			return new SortBySaleAmount();
		}
		return null;
	}

}

class SortByPrice implements Comparator<Products> {
	public int compare(Products o1, Products o2) {
		Integer s1 = o1.getPrice();
		Integer s2 = o2.getPrice();
		return s1.intValue() - s2.intValue();
	}
}

class SortBySaleAmount implements Comparator<Products> {
	public int compare(Products o1, Products o2) {
		Integer s1 = o1.getSaleAmount();
		Integer s2 = o2.getSaleAmount();
		return s1.intValue() - s2.intValue();
	}
}